# # OptionalPartialParameters
module OptionalPartialParameters  
  def self.included(base)
    #base.extend(ClassMethods) 
    base.class_eval do      
      include ClassMethods        
      alias_method_chain :render, :optionals
    end
  end

  module ClassMethods    
    def render_with_optionals(*args)
      options = args.first
      if options.is_a?(Hash)
        options.reverse_merge! :locals => {}
        if options[:partial]
         options[:locals][:opts] = options.delete(:opts) || {}
        end
      end
      render_without_optionals(*args)
    end
  end
end

class Hash
  def with_default(key, default_value)
    self.has_key?(key) ? self[key] : default_value    
  end
end